home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10346 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: question assignment operator in c++
  5. Date: 7 Mar 1996 19:27:08 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4hndac$mgj@dawn.mmm.com>
  8. References: <menghua_wang.1.002DB7BE@muccmail.missouri.edu>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. menghua wang (menghua_wang@muccmail.missouri.edu) wrote:
  13. > I do not why the assignment operator can only be overloaded as a member 
  14. > function in a class such as:
  15.  
  16. >           class myclass {
  17. >               int i;
  18. >           public:
  19. >               myclass operator= (myclass &A) {
  20. >                  i = A.i;
  21. >                  return *this;
  22. >               }
  23. >           };
  24.  
  25. > Why does not the following frind overloading work?
  26.  
  27. >               mycalss operator= (myclass &A, myclass &B) {
  28. >                    A.i = B.i;
  29. >                    return A;
  30. >               }
  31.  
  32. Because the [April draft] standard says that
  33.     An assignment operator shall be implemented by a non-static member
  34.     function with exactly one parameter.
  35. --
  36. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  37. 3M Company                      phone:  (612) 737-4643
  38. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  39. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  40.     But 3M speaks for me -- I did not write the following line:
  41.  
  42. Opinions expressed herein are my own and may not represent those of 3M.
  43.